<template>
  <div id="character-story" :class="{ h5: this.$store.state.webType === 'h5' }">
    <el-row :span="24" class="page">
      <!-- 面包屑 -->
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '/' }">{{
            $t('home')
          }}
        </el-breadcrumb-item>
        <el-breadcrumb-item>{{ $t('sections') }}</el-breadcrumb-item>
        <el-breadcrumb-item>{{ $t('people') }}</el-breadcrumb-item>
      </el-breadcrumb>
<!--      :style="{'background-image': bannerData[currentIndex].imgUrl}"-->
      <div class="banner-view" >
        <el-carousel trigger="click" :arrow="'always'"
                     :initial-index="currentIndex"
                     indicator-position="outside"
                     :height="bannerHeight + 'px'">
          <el-carousel-item v-for="(item, index) in bannerData" :key="index">
            <div class="banner-item"
                 @click="$goDetail(item.id)"
                 :style="{height: '100%',background: `url('${item.imgUrl}') no-repeat  center`, backgroundSize: 'contain'}">
              <div class="item-title" @click="$goDetail(item.id)">
                {{ item.title }}
              </div>
            </div>
          </el-carousel-item>
        </el-carousel>
      </div>

      <el-row :span="24" class="art-row">
        <div class="art-col">
          <!-- 文章label的tab -->
          <div class="art-tab">
            <div
              class="tab-item"
              @click="changeLabel('', '')"
              :class="{ active: currentLabel == '' }"
            >
              {{ $t('all') }}
            </div>
            <template v-if="labelData && labelData.length > 0">
              <div
                class="tab-item"
                @click="changeLabel(item.id, item.label)"
                :class="{ active: currentLabel == item.label }"
                v-for="(item, index) in labelData"
                :key="index"
              >
                {{ item.label }}
              </div>
            </template>
            <!-- 右侧切换视图和总条数 -->
            <div class="tab-info">
              <div class="info-total">
                {{
                  $t('results').length > 6
                    ? listTotal + ' ' + $t('results')
                    : `共
                ${listTotal} 条`
                }}
              </div>
              <div class="toggle-img" @click="viewTypeChange('img')">
                <img
                  v-if="currentView !== 'img'"
                  src="@/assets/images/use/art-view01.png"
                  title="图文列表"
                />
                <img
                  v-if="currentView === 'img'"
                  src="@/assets/images/use/art-view11.png"
                  title="图文列表"
                />
              </div>
              <div class="toggle-text" @click="viewTypeChange('text')">
                <img
                  v-if="currentView !== 'text'"
                  src="@/assets/images/use/art-view02.png"
                  title="文字列表"
                />
                <img
                  v-if="currentView === 'text'"
                  src="../assets/images/use/art-view22.png"
                  title="文字列表"
                />
              </div>
            </div>
          </div>
          <infinite-scroll class="infinite" @loadBottom="loadMore">
            <div
              class="art-view"
              v-masonry
              :horizontal-order="true"
              transition-duration="0s"
              item-selector=".art-item"
              :fit-width="false"
              :gutter="gutterWidth"
              style="height: auto"
              :class="{ text: currentView === 'text' }"
            >
              <template v-if="currentView === 'img'">
                <div
                  class="art-item scale-view"
                  v-masonry-tile
                  v-for="(img, idx) in artData"
                  @click="$goDetail(img.id)"
                  :key="idx"
                >
                  <img :src="img.imgUrl" :alt="img.title"/>
                  <div class="art-content">
                    <div class="item-title two-line">
                      {{ img.title }}
                    </div>
                    <div class="item-info">
                      <div
                        class="info-label"
                        v-if="
                          img.label &&
                          img.label.length > 0 &&
                          $store.state.lang === 'CN'
                        "
                      >
                        {{ currentLabel ? currentLabel : img.label[0] }}
                      </div>
                      <div class="info-time">{{ img.peridos }}</div>
                    </div>
                    <div class="item-content">{{ img.content }}</div>
                  </div>
                </div>
              </template>
              <template v-else>
                <div
                  class="art-item"
                  v-masonry-tile
                  @click="$goDetail(img.id)"
                  v-for="(img, idx) in artData"
                  :key="idx"
                >
                  <div class="art-content">
                    <div class="item-title">
                      {{ img.title }}
                      <div class="item-info">
                        <div
                          class="info-label"
                          v-if="
                            img.label &&
                            img.label.length > 0 &&
                            $store.state.lang === 'CN'
                          "
                        >
                          {{ currentLabel ? currentLabel : img.label[0] }}
                        </div>
                        <div class="info-time">{{ img.peridos }}</div>
                      </div>
                    </div>
                    <div class="item-content">{{ img.content }}</div>
                  </div>
                </div>
              </template>
              <div
                v-if="listQuery.pageNum < maxPage"
                class="art-more true"
                @click="getListMore()"
              >
                {{ $t('more2') }} >
              </div>
              <div v-else class="art-more none">{{ $t('noMore') }}</div>

              <goTop></goTop>
            </div>
          </infinite-scroll>
        </div>
        <!-- 右侧{{$t('latest')}} 热点文章 -->
        <div class="row-right">
          <!-- {{$t('latest')}} -->
          <hot-article></hot-article>
          <new-book></new-book>
        </div>
      </el-row>
    </el-row>
  </div>
</template>

<script>
import goTop from '../components/goTop';
import HotArticle from '@/components/HotArticle';
import NewBook from '@/components/NewBook';
import image from 'element-ui/packages/image';

export default {
  name: 'CharacterStory',
  computed: {
    image() {
      return image;
    }
  },
  components: {
    goTop,
    HotArticle,
    NewBook,
  },
  data() {
    return {
      busy: true,
      nomore: false,
      gutterWidth: 20,

      bannerHeight: 0, // 轮播图容器高度;
      // 左侧大图
      bigBanner: {},
      // banner数据
      bannerData: [],
      // 当前展示的banner index
      currentIndex: 0,
      // {{$t('latest')}}
      bookData: {},
      // 热点文章
      articleData: [],
      // 当前文章列表展示形式
      currentView: 'img',
      // 文章列表
      artData: [],
      // 文章总数量
      listTotal: 0,
      maxPage: 1,
      // 文章列表请求信息
      listQuery: {
        columnId: '',
        labelId: '',
        pageSize: 10,
        pageNum: 1,
      },
      // 标签
      labelData: [],
      currentLabel: '',
    };
  },
  mounted() {
    this.screenWidth = window.innerWidth;
    this.bannerHeight = (730 / 1920) * this.screenWidth;
    console.log('bannerHeight', this.bannerHeight);
    if (this.$store.state.webType === 'h5') {
      this.bannerHeight += 42;
    }
    // 窗口大小发生改变
    window.onresize = () => {
      this.screenWidth = window.innerWidth;
      this.bannerHeight = (730 / 1920) * this.screenWidth;
      if (this.$store.state.webType === 'h5') {
        this.bannerHeight += 42;
      }
    };
    if (this.$route.query.token) {
      sessionStorage.setItem('token', this.$route.query.token);
    }
    this.listQuery.columnId = this.$getPartId(this.$route.path);
    this.listQuery.menuId = this.$getMenuId(this.$route.path);
    this.getList();
    this.getBanner();
    this.getLabels();
  },
  methods: {
    async loadMore() {
      // console.log(
      //   "loadMore",
      //   this.busy || this.listQuery.pageNum >= this.maxPage
      // );
      if (this.busy || this.listQuery.pageNum >= this.maxPage) return;
      this.busy = true;
      this.listQuery.pageNum += 1;
      await this.getList();
    },
    async getList() {
      this.$get(this.$api + '/cms/web/selsctWeb', this.listQuery)
        .then(
          (res) => {
            this.artData = [...this.artData, ...res.data];
            this.listTotal = res.total;
            this.maxPage = res.maxPage;

            let that = this;
            this.$nextTick(() => {
              that.nomore = true;
              setTimeout(() => {
                that.busy = false;
              }, 300);
            });
          }
        );
    },
    changeLabel(id, label) {
      this.listQuery.labelId = id;
      this.listQuery.pageNum = 1;
      this.currentLabel = label;
      this.artData = [];
      this.getList();
    },
    getLabels() {
      this.$get(this.$api + '/cms/web/getLabelByPartId', {
        partId: this.listQuery.columnId,
      })
        .then((res) => {
          this.labelData = res.data;
        });
    },
    getListMore() {
      this.listQuery.pageNum += 1;
      this.getList();
    },
    getBanner() {
      this.$get(this.$api + '/cms/web/partArticleBanner', {
        menuId: this.listQuery.menuId,
      })
        .then((res) => {
          this.bannerData = res.data;
          console.log('bannerData', this.bannerData);
          // res.data.forEach((item, index) => {
          //   if (index === 0) {
          //     this.bigBanner = item;
          //   } else {
          //     this.bannerData.push(item);
          //   }
          // });
          //  console.log(res, this.bigBanner, this.bannerData);
        });
    },
    viewTypeChange(type) {
      this.artData = [];
      this.listQuery.pageNum = 1;
      this.getList();
      this.currentView = type;
      this.$nextTick(() => {
        this.$redrawVueMasonry();
      });
    },
  },
};
</script>
<style lang="scss">
.en #character-story .banner-view .content-html p,
.en #character-story .banner-view .content-html article {
  font-family: "Times New Roman", Times, serif !important;
  font-size: fh(16vh, pc);
}

</style>
<style lang="scss" scoped>

#character-story {
  position: relative;
  width: 100%;
  background-color: rgba(15, 0, 0, 0.5);

  &::after {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    z-index: -1;
    width: 100%;
    height: 100%;
  }

  .page {
    padding: fh(152vh, pc) fw(80vw, pc) fh(40vh, pc) fw(80vw, pc);
    background: #fff;

    ::v-deep .el-breadcrumb {
      // margin-left: fw(-40vw, pc);
      .el-breadcrumb__inner {
        font-weight: bold;
        color: #fff !important;
        font-size: fh(18vh, pc);
      }
    }
  }

  .art-row {
    display: flex;
    padding-top: fh(28vh, pc);
    width: 100%;
  }

  .art-col {
    position: relative;
    width: fw(1180vw, pc);
    margin-top: fh(20vh, pc);

    .art-tab {
      width: 100%;
      display: flex;
      align-items: center;
      margin-bottom: fh(30vh, pc);
      color: $sh;

      .tab-item {
        margin-right: fw(60vw, pc);
        font-size: fh(16vh, pc);
        position: relative;
        line-height: fh(24vh, pc);

        &:hover {
          color: $sh;
          cursor: pointer;
        }

        &.active {
          font-size: fh(20vh, pc);
          font-weight: bold;
          color: $sh;

          &::before {
            content: "";
            position: absolute;
            bottom: fh(-14vh, pc);
            width: 100%;
            border-top: fh(6vh, pc) solid $zh;
          }
        }
      }

      .tab-info {
        margin-left: auto;
        display: flex;
        align-items: center;

        .toggle-img {
          margin-left: fh(62vw, pc);
          margin-right: fh(24vw, pc);
        }

        img {
          width: fw(20vw, pc);
          cursor: pointer;
        }
      }
    }

    .art-view {
      cursor: pointer;

      &.text {
        .art-item {
          width: 100%;
        }

        .item-title {
          color: $sh;
          display: flex;
          width: 100%;

          .item-info {
            padding-left: fw(40vw, pc);
            margin-left: auto;
            width: max-content !important;

            .info-label {
              margin-right: fw(20vw, pc);
              width: max-content !important;
            }

            .info-time {
              width: max-content;
              margin-left: fw(20vw, pc) !important;
            }
          }
        }
      }

      .art-item {
        // break-inside: avoid;
        width: calc((100% - 40px) / 3);
        margin-bottom: fh(20vh, pc);
        background-color: $dh;

        &:hover {
          opacity: 0.9;
        }

        cursor: pointer;

        img {
          width: 100%;
        }

        .art-content {
          width: 100%;
          color: $sh;
          padding: fh(20vh, pc) fw(20vw, pc);
          position: relative;
          z-index: 2;
          background-color: $dh;

          .item-title {
            color: $sh;
            line-height: 130%;
            height: fh(40vh, pc);
            font-size: fh(16vh, pc);
            margin-bottom: fh(8vh, pc);
            font-weight: 600;
          }

          .item-info {
            display: flex;
            align-items: center;
            width: 100%;
            justify-content: space-between;
            margin-bottom: fh(0vh, pc);
            font-size: fh(14vh, pc);
            line-height: fh(20vh, pc);

            .info-time {
              color: #a1b8bd;
              margin-left: auto;
            }
          }

          .item-content {
            font-size: fh(14vh, pc);
            line-height: fh(20vh, pc);
            font-weight: 400;
            width: 100%;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
          }
        }
      }
    }

    .art-more {
      width: max-content;
      margin: fh(40vh, pc) auto;
      color: $sh;
      font-size: fh(14vh, pc);

      &.true:hover {
        cursor: pointer;
        opacity: 0.8;
        color: $zh;
      }

      &.none {
        opacity: 0.5;
      }
    }
  }

  .row-right {
    flex: 1;
    margin-left: fw(20vw, pc);
  }

  .banner-view {
    width: 100vw;
    margin-top: fh(16vh, pc);
    margin-bottom: fh(30vh, pc);
    position: relative;
    left: fw(-80vw, pc);
    background-size: 100% auto;
    background-repeat: no-repeat;
    background-position: center 0;
    .banner-item {
      cursor: pointer;
    }

    ::v-deep .el-carousel {
      width: 100%;
      position: static;
      background-color: #F1F4F5;
      .el-carousel__arrow {
        background-color: rgba(255, 255, 255, 0);
        i {
          color: #0046B4;
          font-size: 40px;
        }
      }
      .el-carousel__indicators--horizontal {
        position: absolute;
        bottom: fh(-40vh, pc);


        //.#A1B8BD
        .el-carousel__button {
          background-color: #0046B4;
          width: 40px;
          height: 4px;
          border-radius: 2px;
        }
      }
    }

    .item-title {
      width: 100%;
      // height: fh(68vh, pc);
      padding: 16px;
      text-align: center;
      position: absolute;
      left: 0;
      bottom: 0;
      color: $zh;
      font-weight: bold;
      font-size: fh(24vh, pc);
      line-height: fh(36vh, pc);
      background: rgba(0, 0, 0, 0.3);
      color: #fff;
      cursor: pointer;

      &:hover {
        opacity: 0.8;
      }
    }

    .item-content {
      flex: 1;
      padding: fw(20vw, pc);

      .more {
        position: absolute;
        bottom: fw(20vw, pc);
        right: fw(20vw, pc);
        font-size: fh(14vh, pc);
        font-weight: 600;
        color: #686a67;
        line-height: fh(20vh, pc);
        cursor: pointer;

        &:hover {
          opacity: 0.8;
        }
      }
    }

    ::v-deep .content-html {
      word-wrap: break-word;
      overflow: hidden;
      height: fh(288vh, pc);
      color: $sh !important;

      strong {
        color: $sh;
      }

      p,
      article,
      section {
        font-size: fh(14vh, pc);
        font-family: "宋体", "songti", "宋体-简", "serif", "sans-serif",
        "cursive", "fantasy", "monospace";
        font-weight: 400;
        color: $sh;
        line-height: fh(24vh, pc) !important;
        margin-top: fh(24vh, pc) !important;
      }

      img,
      img + p,
      img + font,
      p font {
        max-width: 100%;
        display: none;
      }

      strong {
        background-color: rgba(255, 255, 255, 0) !important;
      }

      .html-title {
        font-size: fh(16vh, pc);
        font-weight: bold;
        color: #ffffff;
        line-height: fh(24vh, pc);
      }
    }

    .two-col {
      display: flex;
      align-items: flex-start;
      flex-wrap: wrap;
      flex: 1;
      justify-content: space-between;

      .two-item {
        height: fh(280vh, pc);
        position: relative;
        width: 100%;
        display: flex;
        align-content: flex-start;
        background-color: #f6f6f6;

        &:nth-last-child(1) {
          margin-top: fh(40vh, pc);
        }

        .scale-view {
          width: fw(350vw, pc);
        }

        img {
          width: fw(350vw, pc);
          display: block;
          height: 100%;
        }
      }
    }
  }
}

#character-story.h5 {
  .row-right {
    margin-left: 0;
  }

  .art-col {
    margin-top: 0;

    .art-view {
      &.text {
        .art-item {
          width: 100%;
        }
      }

      .art-item {
        width: calc(50% - 10px);
        margin-bottom: fw(8vw, h5);

        .art-content {
          padding: fw(8vw, h5) !important;
        }
      }
    }
  }

  .banner-view {
    flex-wrap: wrap;
    .item-title {
      padding: 4px;
      font-size: 16px;
      line-height: 22px;
    }
    ::v-deep .el-carousel__indicators--horizontal {
      left: 50%;
      transform: translateX(-50%);
      .el-carousel__button {
        width: 28px;
        height: 2px;
        bottom: -10px;
      }
    }
    .banner-col {
      width: 100%;
      margin-bottom: fh(5vh, h5);
      flex-wrap: wrap;
      height: auto !important;

      > div {
        width: 100%;
      }

      .item-content {
        padding: fh(20vh, h5) fw(10vw, h5);
        padding-bottom: fh(40vh, h5);



        .more {
          bottom: fh(12vh, h5);
          right: fw(10vw, h5);
        }
      }

      .banner-big {
        width: 100%;
        height: auto !important;
      }
    }

    .two-col {
      width: 100%;

      .two-item {
        width: 49%;
        margin-bottom: fh(5vh, h5);

        .item-title {
          color: $sh;
          width: 100%;
          padding: fw(4vw, h5) fw(4vw, h5) !important;
          height: max-content;
          line-height: fh(20vh, h5);
          font-size: fh(14vh, h5);
        }
      }
    }
  }
}
</style>

